package com.oop.demo;

import java.util.Scanner;

/**
 * @author miao
 * @version 1.0
 * @date 2025/4/14 16:01
 * @description
 */
public class Demo2 {
    public static void main(String[] args) {
        //筛选字符串
        //定义数组存入多个字符串
        String[] arr = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
        //删除长度大于5的字符串，打印删除后的数组
        for (int i = 0; i < arr.length; i++) {
            String s = arr[i];
            if (s.length() > 5) {
                arr[i] = null;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            String s = arr[i];
            if (s != null) {
                System.out.println(s);
            }
        }

    }
    public static void main2(String[] args) {
        //键盘录入一个字符串
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str = sc.nextLine();
        //在录入一个字符串
        System.out.println("请再次输入一个字符串：");
        String str1 = sc.nextLine();
        //删除str中的str1
        str = str.replace(str1, "");
        System.out.println(str);

    }
    public static void main1(String[] args) {
//生成一个字符串
        String str = "ea G H D A DDd ajh123";
        //获取大写字母
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= 'A' && c <= 'Z') {
                count++;
            }
        }
        //获取小写字母
        int count1 = 0;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= 'a' && c <= 'z') {
                count1++;
            }
        }
        //获取数字
        int count2 = 0;
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (c >= '0' && c <= '9') {
                count2++;
            }
        }
        //输出大写字母、小写字母、数字的个数

        System.out.println("大写字母的个数为：" + count);
        System.out.println("小写字母的个数为：" + count1);
        System.out.println("数字的个数为：" + count2);
        //判断字符串中指定某一个字符的个数
        char c = 'a';
        int count3 = 0;
        for (int i = 0; i < str.length(); i++) {
            char c1 = str.charAt(i);
            if (c1 == c) {
                count3++;
            }
        }
        System.out.println("字符" + c + "的个数为：" + count3);
        //模拟trim()方法的实现，忽略字符串中的空格
        String str1 = "   a   b   c   ";
        String str2 = "";
        for (int i = 0; i < str1.length(); i++) {
            char c1 = str1.charAt(i);
            if (c1 != ' ') {
                str2 += c1;
            }
        }
        System.out.println(str2);

    }

}
